<script>
import {defineComponent} from 'vue'

export default {
  props: {
    column: {
      type: Object,
      default: {
        setting: {
          prefix: '',
          suffix: ''
        }
      }
    },
  },
  data(){
    return {
      /**
       * 区间值
       */
      intervalValue: [null,null]
    }
  },
  methods: {
    intervalValueChange(column) {
      this.$emit('searchValueChange', column, [parseInt(this.intervalValue[0]),parseInt(this.intervalValue[1])]);
    },
    searchValueChange(column, value) {
      this.$emit('searchValueChange', column, value);
    },
    getBodyData() {
      this.$emit('getBodyData')
    },
    /**
     * 对column进行处理
     * @param column 列的配置
     * @returns {*} 返回处理后的列的配置
     */
    newColumn(column) {
      // 如果column.setting不存在，就给它赋值一个空对象
      if (!column.setting) {
        column.setting = {}
      }
      // 如果前缀不存在，就给它赋值一个默认值
      if (!column.setting.prefix) {
        column.setting.prefix = ''
      }
      // 如果后缀不存在，就给它赋值一个默认值
      if (!column.setting.suffix) {
        column.setting.suffix = ''
      }

      // 如果column.searchSetting不存在，就给它赋值一个空对象
      if(!column.searchSetting){
        column.searchSetting = {}
      }

      // 如果操作符不存在，就给它赋值一个默认值
      if(!column.searchSetting.operatorCode){
        column.searchSetting.operatorCode = 'eq'
      }



      return column
    },
  }
}
</script>

<template>
  <a-input
      v-if="newColumn(column).searchSetting.operatorCode === 'eq'"
      :placeholder="column.placeholder"
      @input="searchValueChange(column, $event.target.value)"
      @keyup.enter.native="getBodyData()"
      type="number"
      allow-clear
  >
        <!--  判断是否有前缀  -->
        <template
            v-if="newColumn(column).setting.prefix"
            #prefix>
          <span class="pa-span">
            {{newColumn(column).setting.prefix}}
          </span>
        </template>

        <!--  判断是否有后缀  -->
        <template
            v-if="newColumn(column).setting.suffix"
            #suffix>
          <span class="pa-span">
            {{newColumn(column).setting.suffix}}
          </span>
        </template>


  </a-input>
<!-- 如果等于闭区间  -->
    <el-row v-if="newColumn(column).searchSetting.operatorCode === 'closeInterval'">
      <el-col :span="11">
        <el-input
            :placeholder="column.placeholder"
            v-model="intervalValue[0]"
            @input="intervalValueChange(column, intervalValue)"
            @keyup.enter.native="getBodyData()"
            allow-clear
        >
        </el-input>
      </el-col>
      <el-col :span="2" class="text-center">
        <div style="text-align: center">~</div>
      </el-col>
      <el-col :span="11">
        <el-input
            :placeholder="column.placeholder"
            v-model="intervalValue[1]"
            @input="intervalValueChange(column, intervalValue)"
            @keyup.enter.native="getBodyData()"
            type="number"
            allow-clear>
        </el-input>
      </el-col>
    </el-row>
</template>

<style lang="scss" scoped>
@import "../../index";
</style>